﻿#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

typedef double Real;
typedef long long MyInt;

typedef struct {
	int sign;
	int n;
	int buf[255];
}HexS;

typedef struct TContext_s
{
	HexS hex;
}TContext;

TContext context;


void read_data(TContext* ctx)
{
	char c;
	int i=0;
	while (scanf("%c", &c))
	{
		if (c == '#')
			break;
		if ('0' <= c && c <= '9')
			ctx->hex.buf[i++] = c - '0';
		else if ('a' <= c && c <= 'f')
			ctx->hex.buf[i++] = c - 'a' + 10;
		else if ('A' <= c && c <= 'F')
			ctx->hex.buf[i++] = c - 'A' + 10;
		else if (c == '-' && i == 0)
			ctx->hex.sign = -1;
	}
	ctx->hex.n = i;
}
 
void do_task(TContext* ctx)
{
	int s = 0;
	for (int i = 0; i < ctx->hex.n  ; ++i)
	{
		s = s * 16 + ctx->hex.buf[i];
	}
	if (ctx->hex.sign < 0 && s!=0)
		printf("-");
	printf("%d\n", s);
}

void solve(TContext* ctx)
{
	read_data(ctx);
	do_task(ctx);
}

int main()
{
	freopen("D:/Develop/GitRepos/MOOC/浙江大学/数据结构/201906/DataStructure/M2019秋C入门和进阶练习集/7-148.txt", "r", stdin);
	solve(&context);
	return 0;
}
